import moment from 'moment'

export const formatBoolean = (bool) => {
  if (bool !== null) {
    return bool ? '是' : '否'
  } else {
    return ''
  }
}
export const formatDateXie = (time) => {
  if (time !== null && time !== '') {
    return moment(time).format('YYYY/MM/DD')
  } else {
    return ''
  }
}

export const formatDate = (time,frm) => {
  if (time !== null && time !== '') {
    if(frm){
      return moment(time).format(frm)
    }else{
      return moment(time).format('YYYY-MM-DD')
    }
  } else {
    return ''
  }
}

export const formatDateDD = (time) => {
  if (time !== null && time !== '') {
    return moment(time).format('YYYY.MM.DD')
  } else {
    return ''
  }
}

export const formatDateWithTime = (time) => {
  if (time !== null && time !== '') {
    return moment(time).format('MM月DD')
  } else {
    return ''
  }
}
export const formatDateLong = (time) => {
  if (time !== null && time !== '') {
    return moment(time).format('YYYY-MM-DD HH:mm:ss')
  } else {
    return ''
  }
}

export const formatDateLongDD = (time) => {
  if (time !== null && time !== '') {
    return moment(time).format('YYYY.MM.DD HH:mm:ss')
  } else {
    return ''
  }
}
// 手机加星号
export const phoneReplace = (value) => {
  if (value && value != '') {
    var str = value
    if (value.length >= 7) {
      str = value.substr(0, 3) + '****' + value.substr(-4)
    } else if (value.length > 5 && value.length < 7) {
      str = value.substr(0, 2) + '****' + value.substr(-2)
    }
    return str
  }
}

export const dateToWeek = (value) => {
  if (value && value != '') {
    const num = moment(value).day()
    switch (num) {
      case 0:
        return '星期日'
      case 1:
        return '星期一'
      case 2:
        return '星期二'
      case 3:
        return '星期三'
      case 4:
        return '星期四'
      case 5:
        return '星期五'
      case 6:
        return '星期六'
      default:
        return ''
    }
  }
}

export const dataToHHmm = (time) => {
  if (time !== null && time !== '') {
    return moment(time).format('HH:mm')
  } else {
    return ''
  }
}

